package com.ysqcould.members.service.impl;


import com.ysqcould.common.utils.DateUtils;
import com.ysqcould.members.domain.Apply;
import com.ysqcould.members.mapper.ApplyMapper;
import com.ysqcould.members.service.IApplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.TreeSet;
import java.util.stream.Collector;
import java.util.stream.Collectors;

/**
 * 入会申请Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-06-29
 */
@Service
public class ApplyServiceImpl implements IApplyService
{
    @Autowired
    private ApplyMapper applyMapper;

    /**
     * 查询入会申请
     * 
     * @param id 入会申请主键
     * @return 入会申请
     */
    @Override
    public Apply selectApplyById(Long id)
    {
        return applyMapper.selectApplyById(id);
    }

    /**
     * 查询入会申请列表
     * 
     * @param apply 入会申请
     * @return 入会申请
     */
    @Override
    public List<Apply> selectApplyList(Apply apply)
    {
        List<Apply> applies = applyMapper.selectApplyList(apply);
        List<Apply> list = applies.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(
                () -> new TreeSet<>(Comparator.comparing(Apply::getUserId))), ArrayList::new));
        return list;
    }

    /**
     * 新增入会申请
     * 
     * @param apply 入会申请
     * @return 结果
     */
    @Override
    public int insertApply(Apply apply)
    {
        apply.setCreateTime(DateUtils.getNowDate());
        return applyMapper.insertApply(apply);
    }

    /**
     * 修改入会申请
     * 
     * @param apply 入会申请
     * @return 结果
     */
    @Override
    public int updateApply(Apply apply)
    {
        apply.setUpdateTime(DateUtils.getNowDate());
        return applyMapper.updateApply(apply);
    }

    /**
     * 批量删除入会申请
     * 
     * @param ids 需要删除的入会申请主键
     * @return 结果
     */
    @Override
    public int deleteApplyByIds(Long[] ids)
    {
        return applyMapper.deleteApplyByIds(ids);
    }

    /**
     * 删除入会申请信息
     * 
     * @param id 入会申请主键
     * @return 结果
     */
    @Override
    public int deleteApplyById(Long id)
    {
        return applyMapper.deleteApplyById(id);
    }
}
